﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.ComponentModel.Composition;
using Kooboo.Domain;

namespace Kooboo.Commerce.Repositories
{
    [Export(typeof(IEntityUpdateCommand<IPayment>))]
    public class PaymentUpdateCommand : EntityUpdateCommand<IPayment>
    {
        protected override string TableName
        {
            get
            {
                return "Payment";
            }
        }

        protected override string BuildCondition()
        {
            var ids = this.EntitySet.Select(i => i.MethodName).ToArray();

            if (ids.Length == 0)
            {
                return " 1=2 ";
            }
            else
            {
                var where = " 1=1 ";
                foreach (var id in ids)
                {
                    where += " or MethodName = '" + id.Replace("'", "''") + "' ";
                }

                if (where.Length > 5)
                {
                    where = where.Substring(8);
                }

                return where;
            }
        }
    }
}
